<template></template>

<script>
import { codeList } from '../utils/code'
import { returnArray } from '@/utils/'

export default {
  name: 'minixCommonPicker',
  methods: {
    showCommonPicker(commonFieldName, columnName) {
      this.commonPicker = true
      this.commonFieldName = commonFieldName
      if (Array.isArray(columnName)) {
        this.commonColumns = columnName
      } else {
        this.commonColumns = codeList[columnName]
      }
    },
    commonOnConfirm(field) {
      this.commonPicker = false

      if (this.commonFieldName == 'tdmc') {
        this.csryOnChange(field)
      } else if (this.commonFieldName == 'team') {
        this.teamOnChange(field)
      } else if (this.commonFieldName == 'chlx') {
        this.rylbOnChange(field)
      } else if (this.commonFieldName == 'sfxccs') {
        this.selfUserInfo[this.commonFieldName + 'Value'] = field.value
        this.selfUserInfo[this.commonFieldName] = field.key
        if (field.key == '01') {
          this.showXccs = true
        } else {
          this.showXccs = false
        }
      } else {
        this.selfUserInfo[this.commonFieldName + 'Value'] = field.value
        this.selfUserInfo[this.commonFieldName] = field.key

        // 交通方式影响到站点、送站点、到站航班，送站航班
        this.trafficOnChange(this.commonFieldName, field.key)
        // 是否住宿影响入住日期、离店日期是否填写
        this.zsOnChange(this.commonFieldName, field.key)
        // 是否跟车影响其他行程信息
        this.gcOnChange(this.commonFieldName, field.key)
        this.bsrylbOnChange(this.commonFieldName, field.key)
      }
    },
    trafficOnChange(fieldName, key) {
      //交通方式影响到站和送站必填信息
      if (fieldName == 'traffic_type' && (key == '01' || key == '02')) {
        // 高铁和飞机站点信息要必填
        this.dzRequire = true
        this.szRequire = true
        if (parseInt(this.selfUserInfo.szd) == 5 || parseInt(this.selfUserInfo.dzd) == 5) {
          this.isOther = true
        } else {
          this.isOther = false
        }
      } else if (fieldName == 'traffic_type' && (key == '03' || key == '04')) {
        this.dzRequire = false
        this.szRequire = false
        if (key == '04') {
          this.isOther = true
        } else {
          this.isOther = false
        }
      }
    },
    zsOnChange(fieldName, key) {
      if (fieldName == 'sfzs' && key == '01') {
        this.zsRequire = true
      } else if (fieldName == 'sfzs' && key == '02') {
        this.zsRequire = false
      }
    },
    gcOnChange(fieldName, key) {
      if (fieldName == 'sfgc' && key == '01') {
        this.showFor40 = false
        //选择了跟车，将所有送到站信息都不显示
        this.trafficOnChange('traffic_type', '03')
        //选择了跟车，入住信息都不显示
        this.zsOnChange('sfzs', '02')
      } else if (fieldName == 'sfgc' && key == '02') {
        this.showFor40 = true
        this.trafficOnChange('traffic_type', this.selfUserInfo.traffic_type)
        this.zsOnChange('sfzs', this.selfUserInfo.sfzs)
      } else if (fieldName == 'sfgc' && key === '') {
        this.showFor40 = true
        this.trafficOnChange('traffic_type', this.selfUserInfo.traffic_type)
        this.zsOnChange('sfzs', this.selfUserInfo.sfzs)
      }
    },
    bsrylbOnChange(fieldName, key) {
      if (fieldName == 'bsrylb' && key == '05') {
        // 高校联络员全部都不显示跟车联动以后的信息,所以模拟触发跟车，到站和入站等信息不显示
        this.gcOnChange('sfgc', '01')
        this.showForGxlly = false
      } else {
        // 非高校联络员全部按需触发
        // this.gcOnChange("sfgc",this.selfUserInfo.sfgc)
        this.actionFor40()
        this.showForGxlly = true
      }
    },
    csryOnChange(item) {
      if (item.key == '99') {
        this.isDbd = 1
      } else {
        this.isDbd = ''
      }
      this.selfUserInfo.tdbh = item.key
      this.selfUserInfo.tdmc = item.value
      this.selfUserInfo.tdmc1 = ''
      this.selfUserInfo.chlxValue = ''
      this.selfUserInfo.chlx = ''
      this.selfUserInfo.chlx_xflx = ''
      this.selfUserInfo.chlx_xflxValue = ''

      this.xflxShow = false
      if (item.showChild && item.hasOwnProperty('child')) {
        this.showRylb = true
        this.rylbColumns = returnArray(item.child, 'show', true)
      } else if (!item.showChild) {
        this.showRylb = false
        this.selfUserInfo.chlx = item.child[0].key
      }
      this.showPickerCsry = false
      this.showParttime()
      this.initSpecificField()
    },
    rylbOnChange(item) {
      this.dwChoose = false
      this.isEmail = false
      this.xflxShow = false
      this.schoolChoose = false
      if (item.key == '5') {
        this.isEmail = true
      }
      if (this.selfUserInfo.tdbh == 2 && item.key == 12) {
        this.xflxShow = true
      }
      if (item.key == '18' || item.key == '10') {
        this.dwChoose = true
      }
      if (item.key == '40') {
        this.schoolChoose = true
      }
      this.selfUserInfo.dw = ''
      this.selfUserInfo.dwbh = ''
      this.selfUserInfo.chlx_xflx = ''
      this.selfUserInfo.chlx_xflxValue = ''
      this.selfUserInfo.chlx = item.key
      this.selfUserInfo.chlxValue = item.value
      this.showParttime()
      this.initSpecificField()
      this.showPickerRylb = false
    },
    teamOnChange(item) {
      this.selfUserInfo.tdbh = item.key
      this.selfUserInfo.tdmc1 = item.value
      this.showPickerTeam = false
    }
  }
}
</script>

<style scoped>
</style>
